package main

import (
	"fmt"
	"homework6/htrxgo"
	"time"
)

func main() {
	fmt.Println("输入：10, 20, 30, 40, 50")
	res := []int{}
	ob := htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).Debounce(1000000)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("Debounce结果: ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n\n")

	fmt.Println("输入：10, 20, 30, 40, 50, 30, 40")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50, 30, 40).Map(func(x int) int {
		return x
	}).Distinct()
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("Distinct结果: ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).ElementAt(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Println("ElementAt结果: ", res[0])
	fmt.Print("\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).First()
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Println("First结果: ", res[0])
	fmt.Print("\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).Last()
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Println("Last结果: ", res[0])
	fmt.Print("\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		time.Sleep(2 * time.Millisecond)
		return x
	}).Sample(3 * time.Millisecond).Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("Sample结果: ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).Skip(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("结果: ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).SkipLast(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("SkipLast结果: ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).Take(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("Take结果: ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n\n")

	fmt.Println("输入：10, 20, 30, 40, 50")
	res = []int{}
	ob = htrxgo.Just(10, 20, 30, 40, 50).Map(func(x int) int {
		return x
	}).TakeLast(3)
	ob.Subscribe(func(x int) {
		res = append(res, x)
	})
	fmt.Print("结果: ")
	for _, val := range res {
		fmt.Print(val, "  ")
	}
	fmt.Print("\n")
}
